# -*- coding: utf-8 -*-
"""
@Time ： 2024/8/9 15:02
@Auth ： 李天天
"""
import re

import requests
from Common.handle_log import do_log


def login_vip_partner(token):
    url = "https://passport.iqiyi.com/apis/partner/ott_token_bind.action"
    payload = 'app_version=15.9.5&device_type=Xiaomi%2BPad%2B6&ua=Xiaomi%2BPad%2B6&device_name=Xiaomi-Xiaomi%2BPad%2B6&qyidv2=3633776DD16C193F1E652CE4F3D6AF93&agenttype=21&sdk_version=15.9.5&hui_version=&hfvc=95&lang=zh_CN&s2=WD&s3=top_card&envinfo=&s4=WD_login&fromSDK=21&authcookie=f87tSm1p0S0nZa7Gz2qeWB6EsDG2MN3NEK7llIO9zdZ9JlzxXp5eqbVE0GO0atPvY4q1f&qd_sg=56c9e1f84af2f55857515f57d7c49d80110b-15.9.5-1729565089966-2029073816&ptid=02022001010000000000&version=15.9.5&token=GFxo81%2Fw9s7ZNBWkPASiXYH2AzEFDVNGod%2FGkHTLHJ1Ye0wzEwbFW%2B4hXr0Lb2en9FrCbtbr%2BsFm3ID17GCbPE1W0lsAafwNT%2Bb6Na9soAnHqqVhBgZ%2B3dsD9WxyHYYHK7JdZhR1rFk%2BUO68r2iix9xKivwrtqP5ELQoynfaP0o%3D&dfp=14b79ba7968ff04754b6a0afeb6fc7fac32876413e06af65266076261b56498967&iqid=5bd0138d6bd5b8209ecdbe66ec8c7e941324b001&biqid=56c9e1f84af2f55857515f57d7c49d80110b&qyid=56c9e1f84af2f55857515f57d7c49d80110b&QC005=3633776DD16C193F1E652CE4F3D6AF931729564643507&app_lm=cn'
    headers = {
        'Host': 'passport.iqiyi.com',
        'sign': '98614b6076ab340954db7219dc6fca00',
        'user-agent': 'iqiyi/com.qiyi.video/15.9.5/NetLib-okhttp/3.12.10.20',
        't': '623716740',
        'pass-sign': 'DDEF6A2ADC7EC63C01A5C228304B3CEC_1_0_2988236975',
        'qyid': '56c9e1f84af2f55857515f57d7c49d80110b',
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Accept': '*/*',
        'Connection': 'keep-alive'
    }
    new_token_value = token
    pattern = r'token=[^&]*'
    replacement = f'token={new_token_value}'
    new_payload = re.sub(pattern, replacement, payload)

    response = requests.request("POST", url, headers=headers, data=new_payload)

    do_log.info(f"partner登录请求响应为{response.text}")


def login_regular_partner(token):
    url = "https://passport.iqiyi.com/apis/partner/ott_token_bind.action"
    payload = 'app_version=15.7.5&device_type=Xiaomi%2BPad%2B6&ua=Xiaomi%2BPad%2B6&device_name=Xiaomi-Xiaomi%2BPad%2B6&qyidv2=46C3EB14C920AF77D5BAEC616FC57B9E&agenttype=21&sdk_version=15.7.5&hui_version=&hfvc=95&lang=zh_CN&s2=&s3=&envinfo=&s4=&fromSDK=21&authcookie=bePm2AhSLyr26Meb0QDOm25V3bUH3H0hNclZ7QADsrhsm1wysgF5CVj4j9phnK2Gm3Pf6vf1&qd_sg=2e1c23b45884abb01d4bd20d92b12f171105-15.7.5-1729565109509-1806372581&ptid=02022001010000000000&version=15.7.5&token=GFxo81%2Fw9s7ZNBWkPASiXbD3NMJXsph73WZZKgH%2BoSjdnbboNQ1MEe330vfEh8AM%2FdU%2Bl3FdTJpjDNpNalfQODeUnN%2BLhMuY%2BifAQ4DajVvaxQHfyZEUHXelln5KorG2KIYXMrrDYL5jVL0vYLYHoA%3D%3D&dfp=147c6259d22ed14e849b4f7b027e870a8bfc6ce4141da75c9d13f040e19c456c5b&iqid=7ae56b2ec38130e952b95496a355c01a1120300b&biqid=2e1c23b45884abb01d4bd20d92b12f171105&qyid=2e1c23b45884abb01d4bd20d92b12f171105&QC005=46C3EB14C920AF77D5BAEC616FC57B9E1729565106290&app_lm=cn'
    headers = {
        'Host': 'passport.iqiyi.com',
        'user-agent': 'iqiyi/com.qiyi.videp/15.7.5/NetLib-okhttp/3.12.10.20',
        'pass-sign': 'CE33B62FF896E052BA823E1AD82C2606_1_0_2988256517',
        'qyid': '2e1c23b45884abb01d4bd20d92b12f171105',
        'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',
        'Accept': '*/*',
        'Connection': 'keep-alive',
        'Cookie': 'P00004=.1729565377.5b04d8f63f; QC005=0924d4c4341ff83fa4cba3a1e99967eb'
    }
    new_token_value = token
    pattern = r'token=[^&]*'
    replacement = f'token={new_token_value}'
    new_payload = re.sub(pattern, replacement, payload)

    response = requests.request("POST", url, headers=headers, data=new_payload)

    do_log.info(f"partner登录请求响应为{response.text}")
